﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Ssb
{
    public class Menu 
        : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public Menu(Game game, Menu parent, List<MenuItem> items)
            : base(game)
        {
            Parent = parent;
            Items = items;

            Initialize();
        }

        public Menu Parent;
        public List<MenuItem> Items;

        [ContentSerializerIgnore]
        public Cursor cursor;

        [ContentSerializerIgnore]
        public Texture2D bg;

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            cursor = new Cursor(new Logic.Bubble(new Vector2(2), 2, Game), Game);

            base.Initialize();
        }

        public override void Draw(GameTime gt)
        {
            cursor.Draw(gt);
            ((SpriteBatch)Game.Services.GetService(typeof(SpriteBatch))).Draw(bg, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1, SpriteEffects.None, 1f);

            foreach (MenuItem mi in Items)
            {
                mi.Draw(gt);
            }
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            this.cursor.coords.X = Mouse.GetState().X;
            this.cursor.coords.Y = Mouse.GetState().Y;

            foreach (MenuItem mi in Items)
            {
                Rectangle mirect = new Rectangle((int)mi.coords.X, (int)mi.coords.Y, mi.itemTexture.Width, mi.itemTexture.Height);

                mi.Update(gameTime);
            }

            base.Update(gameTime);
        }
    }
}
